Fix: URLSanitizer allows SSRF via hostnames without DNS/IP revalidation - #1660
Merged
Conversation
|
@Kirtan-pc is attempting to deploy a commit to the Anuj's projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
🎉 Thank you for your contribution! Your Pull Request has been merged successfully. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
Summary
Fix SSRF vulnerability where
URLSanitizer.validate_url()bypassed blocked-network checks for hostname-based URLs (e.g.,http://localhost,http://internal-host.example). The_validate_ip_address()method returned early for non-IP hosts, allowing hostnames that resolve to private IPs to pass validation.Changes
security/url_sanitizer.py_validate_ip_address()now resolves hostnames viasocket.getaddrinfo()and checks all resolved IPs against blocked networks. If resolution fails, anInvalidURLErroris raised.BLOCKED_PORTSset (~80 dangerous ports including SSH:22, MySQL:3306, Redis:6379, Docker:2375, etc.) andallowed_portsconstructor parameter for allowlist-based port control._validate_port()is called duringvalidate_url()._check_blocked_ip: Extracted the blocked-network check into a reusable helper.allowed_portsparameter: Added to bothURLSanitizer.__init__and the conveniencevalidate_url()function.tests/test_security.pyAdded 9 new tests covering:
allow_localhost/allow_privateflags work with hostname-based URLsInvalidURLError🔗 Linked Issue
Closes #1541
📋 Contribution Checklist